﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CustomsSystem.BLL;
using CustomsSystem.Model;
using Maticsoft.Common;
using Microsoft.Win32;
namespace WEB.Bank
{
    public partial class BankAdd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            { bind(); }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        { 
            //验证是否存在该公司
            string CN=tbCustomsName .Text .Trim ();
            CustomsSystem.Model.Customer  ma = new CustomsSystem.BLL.CustomerManage ().GetModel(CN );
            if (ma != null)
            { //保存
              CustomsSystem.Model.Cu_Bank model = new Cu_Bank();
              model.CID = ma.ID;
              model.Bank = tbBank.Text.Trim();
              model.BankNO = tbBankNo.Text.Trim();
              model.Fax = tbFax.Text.Trim();
              model.Phone = tbPhone.Text.Trim();
              model.Remarks = tbRemarks.Text.Trim();
              CustomsSystem.BLL.BankManage BM = new BankManage();
              BM.Add(model);
              MessageBox.Show(this ,"添加成功！");
            
            }
            else
            { MessageBox.Show(this ,"该公司不存在，请确认公司名称是否正确！"); }
            
           
        }

        protected void bind()
        {
            if (Session["CustomerName"] != null && Session["CustomerName"].ToString() != "")
            {
                tbCustomsName.Text = Session["CustomerName"].ToString();
            }
 
        }

      

        #region 自动完成填写公司
        [System.Web.Services.WebMethod]
        [System.Web.Script.Services.ScriptMethod]
        public static string[] GetCustomersName(string prefixText, int count)
        {
            CustomerManage cusManage = new CustomerManage();
            List<string> strArray = new List<string>();
            List<Customer> cusList = cusManage.GetModelList("");
            foreach (Customer aCus in cusList)
            {
                strArray.Add(aCus.CustomerName);
            }
            return (from m in strArray
                    where m.Contains(prefixText)
                    select m).Take(count).ToArray();
        }
        #endregion
    }
}